<?php
	include_once $_SERVER['DOCUMENT_ROOT'] . '/projet_mosquee/AMC/conf/conf.site.inc.php';
	// include_once $_SERVER['DOCUMENT_ROOT'] . '/inscriptions/conf/conf.site.inc.php';

	include_once ELEVE_CLASS;
        include_once PARENT_CLASS;
	include_once FUNCTIONS_FILE;
	include_once INSCRIPTION_CLASS;

	connexion ();

	$paiement = new inscription ($db);

        switch($_POST["action"]) {
            case "nouveau_frais":
                $montant = $_POST["montant_a_payer"];
                $modePaiement = $_POST["type_paiment"];
                $idParent = $_POST["id_parent_frais"];
                $montantDu = $_POST["montant_total"];
                $idFraisInscription = $paiement->newFraisInscription($idParent, $montantDu);
                if ($idFraisInscription){
                    if ($montant != "" && $montant > 0){
                        $idPaiement = $paiement->newPaiment($idFraisInscription, $montant, $modePaiement);
                        $frais_inscription = $paiement->getFraisInscription($idParent, date("Y"));
                        echo json_encode($frais_inscription);
                        // print_r($frais_inscription);
                    }
                    else {
                        echo json_encode(array("code_retour" => 0));
                    }
                }
                else {
                    echo json_encode(array("code_retour" => 0));
                }
                break;

            case "nouveau_paiement":
                $idFraisInscription = $_POST["id_frais_inscription"];
                $montant = $_POST["montant_a_payer"];
                $modePaiement = $_POST["type_paiment"];
                $idParent = $_POST["id_parent_frais"];
                $idPaiement = $paiement->newPaiment ($idFraisInscription, $montant, $modePaiement);
                if ($idPaiement){
                    $frais_inscription = $paiement->getFraisInscription($idParent, date("Y"));
                    echo json_encode($frais_inscription);
                }
                else {
                    echo json_encode(array("code_retour" => 0));
                }
                break;

            case "update_montant":
                var_dump($_POST);
                break;
        }

        $paiement->_inscription();

?>